<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Session\Container;
use Zend\View\Model\JsonModel;
class IndexController extends AbstractActionController
{
    public function indexAction()
    {
		$baseUrls = $this->getServiceLocator()->get('config');
		$baseUrlArr = $baseUrls['urls'];
		$baseUrl = $baseUrlArr['baseUrl'];
		if(isset($_POST['Username']) && $_POST['Username']!=""){
			$usersTable=$this->getServiceLocator()->get('Users\Model\UsersFactory');	
			$request = $this->getRequest();
			$userdetails = $usersTable->checkLogin($request->getPost());
			if($userdetails!=''){			
				$user_session = new Container('user');			
				$user_session->username=$userdetails->user_name;
				$user_session->email=$userdetails->email;
				$user_session->display_name=$userdetails->user_name;
				$user_session->user_id=$userdetails->user_id;
				$user_session->user_type=$userdetails->user_type;			
				$result = new JsonModel(array(					
					'output' 		=> 'success',
				));					
			}else{
				$result = new JsonModel(array(					
					'output' 		=> 'not success',
				));			
			}
			return $result;				
		}
    }	
	public function headerAction($params)
    {
		$baseUrls = $this->getServiceLocator()->get('config');
		$baseUrlArr = $baseUrls['urls'];
		$baseUrl = $baseUrlArr['baseUrl'];
		$basePath = $baseUrlArr['basePath'];
		$paypalUrl = $baseUrlArr['paypalUrl'];
		$paypalid = $baseUrlArr['paypalid'];
		return $this->layout()->setVariable(
			"headerarray",array(
				'baseUrl' 		=> 	$baseUrl,
				'basePath'		=>	$basePath,				
				'paypalUrl'		=>	$paypalUrl,				
				'paypalid'		=>	$paypalid,				
			)
		);
	}
}
